// pages/doctor/detail/detail.js
var docotrservice = require("../../../apiservice/doctor/doctorservice");
const jsonData = require("../jsondata.js");
var doctorId;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		doctorItem: {},
		operationType: jsonData.operationType,
		selectType: []
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

		doctorId = options.doctorId;

	},
	/**
	 * 跳转页面
	 */
	toModifyPage: function() {
		let data = JSON.stringify(this.data.doctorItem);
		wx.navigateTo({
			url: '../modify/modify?data=' + data
		});
	},
	toPromotionPage: function() {
		wx.navigateTo({
			url: '../../promotion/list/list?contactid='+doctorId
		});
	},
	toVisitPage: function() {
		wx.navigateTo({
			url: '../../visit/list/list?contactid=' + doctorId + '&districtid=' + this.data.doctorItem.new_districtandcounty
		});
	},
	toAddPromotionPage: function() {
		wx.navigateTo({
			url: '../../promotion/add/add?contactid=' + doctorId+"&doctorName="+this.data.doctorItem.lastName
			+'&institutionid='+this.data.doctorItem.new_hospitalname
		});
	},
	toAddVisitPage: function() {
		wx.navigateTo({
			url: '../../visit/add/add?contactid=' + doctorId+"&doctorName="+this.data.doctorItem.lastName
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},
  makeCall:function(){
    if (this.data.doctorItem.mobilePhone){
      wx.makePhoneCall({
        phoneNumber: this.data.doctorItem.mobilePhone
      })
    }

  },
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		var that = this;
		docotrservice.GetDoctorById(doctorId).then(function(success) {
			console.log(success);
			var office = jsonData.getOfficeNameByCode(success.data.new_administrativeortechnicaloffices); //科室
			//var job = jsonData.getJobNameByCode(success.data.new_title); //职务
			//console.log(office+","+job);
			var doctorItem = success.data;
			that.setData({
				doctorItem: doctorItem,
				['doctorItem.officeName']: office,
				//['doctorItem.jobName']: job
			});
			that.getSelectItem(doctorItem);
		}).catch(function(ex) {
			console.log(ex);
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	},
	getSelectItem: function(doctorItem) {
		var selectType = [];
		if (doctorItem.new_cataract) {
			selectType.push("1");
		}
		if (doctorItem.new_strabismus) {
			selectType.push("2");
		}
		if (doctorItem.new_glaucoma) {
			selectType.push("3");
		}
		if (doctorItem.new_lacrimalpassage) {
			selectType.push("4");
		}
		if (doctorItem.new_ametropia) {
			selectType.push("5");
		}
		if (doctorItem.new_fundustangent) {
			selectType.push("6");
		}
		this.setData({
			selectType: selectType
		})
	}

})
